//
//  LZFightGroupPopScrollView.m
//  laziz_Consumer
//
//  Created by xbnzd on 17/4/18.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZFightGroupPopScrollView.h"
#import "LZGrabCouponAndFightGroupsDetialModel.h"

#import "LZDateFormatterManager.h"
#import "Masonry.h"


static CGFloat selfWidth = 275.0;

@interface LZFightGroupPopScrollView ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIButton *joinGroupBtn;
@property (nonatomic, strong) UIButton *startNewGroupBtn;

@end

@implementation LZFightGroupPopScrollView

#pragma mark - event
- (void)setBtnsUserInteractionEnabled:(BOOL)enabled
{
    self.joinGroupBtn.userInteractionEnabled = enabled;
    self.startNewGroupBtn.userInteractionEnabled = enabled;
}

- (void)joinGroupBtnAction
{
    if (self.groupTitleViewForPopDelegate && [self.groupTitleViewForPopDelegate respondsToSelector:@selector(joinGroupBtnAction)]) {
        [self.groupTitleViewForPopDelegate joinGroupBtnAction];
    }
}

- (void)startNewGroupBtnAction
{
    if (self.groupTitleViewForPopDelegate && [self.groupTitleViewForPopDelegate respondsToSelector:@selector(startNewGroupBtnAction)]) {
        [self.groupTitleViewForPopDelegate startNewGroupBtnAction];
    }
}

#pragma mark - private method

- (void)setDetailModel:(LZGrabCouponAndFightGroupsDetialModel *)detailModel
{
    _detailModel = detailModel;
    
    [self configureUI];
}

- (void)setLabelContentText:(NSString *)text Label:(UILabel *)glabel
{
    if (text.length <= 0) {
        return;
    }
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentNatural];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    glabel.attributedText = attStr;
}


#pragma mark - UI
- (void)configureUI
{
    GET_SCREEN_SCALE(scale);
    CGFloat textScale = scale;
    
    self.backgroundColor = [UIColor clearColor];
    
    if (self.subviews.count > 0) {
        [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = UIColorFromRGB(0xffffff, 1);
    [self addSubview:bgView];
    
    //底图
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(0);
        make.top.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0);
        make.width.mas_equalTo(selfWidth*scale);
    }];
    
    
    //团购名称  倒计时  参加团购按钮  开启新团按钮  线
    UILabel *groupNameLabel = [self creatLabelWithTextColor:UIColorFromRGB(0xff7a21, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:0];
    groupNameLabel.preferredMaxLayoutWidth = selfWidth*scale - 20;
    groupNameLabel.text = self.detailModel.grouponName;
    [bgView addSubview:groupNameLabel];
    
    self.timeLimitLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x999999, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    self.timeLimitLabel.text = @" ";
    [bgView addSubview:self.timeLimitLabel];
    
    self.joinGroupBtn = [self creatButtonWithTitle:LZLocalizedString(@"group_join_big", nil)];
    [self.joinGroupBtn addTarget:self action:@selector(joinGroupBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:self.joinGroupBtn];
    
    self.startNewGroupBtn = [self creatButtonWithTitle:LZLocalizedString(@"group_start_group_big", nil)];
    [self.startNewGroupBtn addTarget:self action:@selector(startNewGroupBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:self.startNewGroupBtn];
    
    UIView *lineOne = [self creatLine];
    [bgView addSubview:lineOne];
    [self addMasonryWithGroupNamelLabel:groupNameLabel timeLimitLabel:self.timeLimitLabel joinBtn:self.joinGroupBtn startNewGroupBtn:self.startNewGroupBtn line:lineOne];
    
    //******************成团人数  结束时间
 
    UILabel *titleLabelTwo = [self creatLabelWithTextColor:UIColorFromRGB(0x666666, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    titleLabelTwo.text = LZLocalizedString(@"group_order_rules", nil);
    [bgView addSubview:titleLabelTwo];
    
    //成团人数
    UILabel *grouCountTitleLabe = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    grouCountTitleLabe.text = LZLocalizedString(@"group_members_required", nil);
    [bgView addSubview:grouCountTitleLabe];
    
    UILabel *groupCountLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    groupCountLabel.text = self.detailModel.grouponCount;
    [bgView addSubview:groupCountLabel];
    
    //结束时间
    UILabel *groupEndTitleLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    groupEndTitleLabel.text = LZLocalizedString(@"mine_coupons_finsh_time", nil);
    [bgView addSubview:groupEndTitleLabel];
    
    UILabel *groupEndTime = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    groupEndTime.text = [[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.detailModel.grouponEndTime];
    [bgView addSubview:groupEndTime];
    
    UIView *lineTwo = [self creatLine];
    [bgView addSubview:lineTwo];
    
    [self addMasonryWithLastView:lineOne titlelabel:titleLabelTwo groupPeopleCountTitleLabel:grouCountTitleLabe groupPeopleCountLabel:groupCountLabel groupEndTimeTitleLabel:groupEndTitleLabel groupEndTimeLabel:groupEndTime line:lineTwo];

    //**************** 团购规则提醒  过期时间
    UILabel *titleLabelThree = [self creatLabelWithTextColor:UIColorFromRGB(0x666666, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    titleLabelThree.text = LZLocalizedString(@"group_terms_of_use", nil);
    [bgView addSubview:titleLabelThree];
    
    //规则提醒
    UILabel *groupRuleLabel;
    if (self.detailModel.grouponRemindRule.length != 0) {
        groupRuleLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
        groupRuleLabel.preferredMaxLayoutWidth = selfWidth*scale - 20;
        groupRuleLabel.text = self.detailModel.grouponRemindRule;
        [bgView addSubview:groupRuleLabel];
    }
    
    //过期时间
    UILabel *guoQiTitleLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    guoQiTitleLabel.text = LZLocalizedString(@"mine_coupons_expiration_date", nil);
    [bgView addSubview:guoQiTitleLabel];
    
    UILabel *guoQiLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    guoQiLabel.text = [[LZDateFormatterManager shareInstance] stringFromDoubleTimestampHavePointyyyyMMdd:self.detailModel.grouponDeadline];
    [bgView addSubview:guoQiLabel];
    
    UIView *lineThree = [self creatLine];
    [bgView addSubview:lineThree];
    
    [self addMasonryWithLastView:lineTwo titleLabel:titleLabelThree rulesLabel:groupRuleLabel guoQiTitlelabel:guoQiTitleLabel guoQiLabel:guoQiLabel line:lineThree];
    
    //*********** 团购 除外时间 每天有效时间 预约提醒
    UILabel *timeTitleLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x666666, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    timeTitleLabel.text = LZLocalizedString(@"group_meal_time", nil);
    [bgView addSubview:timeTitleLabel];
    
    //团购除外时间
    UILabel *exceptTimeNameLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    exceptTimeNameLabel.text = LZLocalizedString(@"mine_coupons_valid_except", nil);
    [bgView addSubview:exceptTimeNameLabel];
    
    UILabel *exceptTimeLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:0];
    exceptTimeLabel.preferredMaxLayoutWidth = selfWidth*scale - 30 - [exceptTimeNameLabel intrinsicContentSize].width;
    [self setLabelContentText:self.detailModel.grouponExceptTime Label:exceptTimeLabel];
    [bgView addSubview:exceptTimeLabel];
    
    //每天有效时间
    UILabel *everyDayValidNameLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    everyDayValidNameLabel.text = LZLocalizedString(@"mine_coupons_everyday_valid", nil);
    [bgView addSubview:everyDayValidNameLabel];
    
    UILabel *everyDayValidLabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:0];
    everyDayValidLabel.preferredMaxLayoutWidth = selfWidth*scale - 30 - [everyDayValidNameLabel intrinsicContentSize].width;
    [self setLabelContentText:[self.detailModel getGroupEverydayValid] Label:everyDayValidLabel];
    [bgView addSubview:everyDayValidLabel];
    
    //预约提醒
    UILabel *otherContentLable;
    if (self.detailModel.grouponRemindAppoint.length != 0) {
        otherContentLable = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:0];
        otherContentLable.preferredMaxLayoutWidth = selfWidth*scale - 20;
        [self setLabelContentText:self.detailModel.grouponRemindAppoint Label:otherContentLable];
        [bgView addSubview:otherContentLable];
    }
    
    //线
    UIView *lineFour = [self creatLine];
    [bgView addSubview:lineFour];
    
    [self addMasonryWithLastView:lineThree titleLabel:timeTitleLabel exceptNameLabel:exceptTimeNameLabel exceptTimeLabel:exceptTimeLabel validNameLabel:everyDayValidNameLabel validTimeLabel:everyDayValidLabel otherContentLabel:otherContentLable line:lineFour];
    
    
    //************ 餐厅名称
    UILabel *resNameTitlelabel = [self creatLabelWithTextColor:UIColorFromRGB(0x666666, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:1];
    resNameTitlelabel.text = LZLocalizedString(@"group_publisher", nil);
    [bgView addSubview:resNameTitlelabel];
    
    UILabel *resNamelabel = [self creatLabelWithTextColor:UIColorFromRGB(0x333333, 1) Font:[UIFont fontWithName:@"ArialMT" size:15*textScale] NumberLines:0];
    resNamelabel.preferredMaxLayoutWidth = selfWidth*scale - 20;
    [self setLabelContentText:self.detailModel.restaurantName Label:resNamelabel];
    [bgView addSubview:resNamelabel];
    
    UIView *lineFive = [self creatLine];
    [bgView addSubview:lineFive];
    lineFive.backgroundColor = [UIColor clearColor];
    
    [self addMasonryWithLastView:lineFour resNameTitleLabel:resNameTitlelabel resNameLabel:resNamelabel line:lineFive];
    
    
    //*****更新底图高度
    [bgView layoutIfNeeded];
    
    CGFloat maxY= lineFive.frame.origin.y;
    if (maxY < 348*scale) {
        maxY = 350.0;
    }
    [bgView updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(maxY);
    }];
    
   
    //高斯模糊
//    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
//    UIVisualEffectView *visulView = [[UIVisualEffectView alloc] initWithEffect:effect];
//    
//    [bgView insertSubview:visulView atIndex:0];
//    [visulView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.top.trailing.mas_equalTo(0);
//        make.bottom.mas_equalTo(300);
//    }];
//
    
    UIView *whiteBgView = [[UIView alloc] init];
    whiteBgView.backgroundColor = UIColorFromRGB(0xffffff, 1);
    [bgView insertSubview:whiteBgView atIndex:0];
    [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(300);
    }];
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    DLog(@"=======================%lf",scrollView.contentOffset.y);
}


#pragma mark - -----------------   masonry   ------------------
#pragma mark  团购名称 倒计时. 参团按钮 开新团按钮 线
- (void)addMasonryWithGroupNamelLabel:(UILabel *)groupNameLabel timeLimitLabel:(UILabel *)timeLabel joinBtn:(UIButton *)joinBtn startNewGroupBtn:(UIButton *)startNewGroupBtn line:(UIView *)line
{
    GET_SCREEN_SCALE(scale);
    [groupNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.mas_equalTo(15);
        make.trailing.mas_equalTo(-10);
    }];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(groupNameLabel);
        make.top.equalTo(groupNameLabel.mas_bottom).offset(8);
    }];
    
    [joinBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(120*scale, 36));
        make.top.equalTo(timeLabel.mas_bottom).offset(13);
        make.leading.mas_equalTo(10);
    }];
    
    [startNewGroupBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(120*scale, 36));
        make.top.equalTo(timeLabel.mas_bottom).offset(13);
        make.trailing.mas_equalTo(-10);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(startNewGroupBtn.mas_bottom).offset(15);
    }];
}

#pragma mark - 添加  成团人数  结束时间 label的约束
- (void)addMasonryWithLastView:(UIView *)lastView titlelabel:(UILabel *)titlelabel groupPeopleCountTitleLabel:(UILabel *)countTitleLabel groupPeopleCountLabel:(UILabel *)countLabel groupEndTimeTitleLabel:(UILabel *)endTimeTitleLabel groupEndTimeLabel:(UILabel *)groupEndTimeLabel line:(UIView *)line
{
    [titlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lastView.mas_bottom).offset(15);
        make.leading.mas_equalTo(10);
    }];
    
    [countTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.equalTo(titlelabel.mas_bottom).offset(13);
    }];
    
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(countTitleLabel.mas_trailing).offset(10);
        make.trailing.lessThanOrEqualTo(-10);
        make.top.equalTo(countTitleLabel);
    }];
    
    [endTimeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.equalTo(countLabel.mas_bottom).offset(13);
    }];
    
    [groupEndTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(endTimeTitleLabel.mas_trailing).offset(10);
        make.trailing.lessThanOrEqualTo(-10);
        make.top.equalTo(endTimeTitleLabel);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.top.equalTo(groupEndTimeLabel.mas_bottom).offset(15);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark - 添加 团购  规则提醒 过期时间 label 约束
- (void)addMasonryWithLastView:(UIView *)lastView titleLabel:(UILabel *)titleLabel rulesLabel:(UILabel *)rulesLabel guoQiTitlelabel:(UILabel *)guoQiTitleLabel guoQiLabel:(UILabel *)guoQiLabel line:(UIView *)line
{
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.equalTo(lastView.mas_bottom).offset(15);
    }];
    
    UIView *lastLabel = titleLabel;
    if (rulesLabel) {
        lastLabel = rulesLabel;
        [rulesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(10);
            make.trailing.mas_equalTo(-10);
            make.top.equalTo(titleLabel.mas_bottom).offset(13);
        }];
    }
    
    
    [guoQiTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.equalTo(lastLabel.mas_bottom).offset(10);
    }];
    
    [guoQiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(guoQiTitleLabel.mas_trailing).offset(10);
        make.trailing.lessThanOrEqualTo(-10);
        make.top.equalTo(guoQiTitleLabel);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.top.equalTo(guoQiLabel.mas_bottom).offset(15);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark - 添加 团购, 除外时间, 每天有效时间, 预约提醒 label 约束
- (void)addMasonryWithLastView:(UIView *)lastView titleLabel:(UILabel *)titleLabel exceptNameLabel:(UILabel *)exceptNameLabel exceptTimeLabel:(UILabel *)exceptTimeLabel validNameLabel:(UILabel *)validNameLabel validTimeLabel:(UILabel *)validTimeLabel otherContentLabel:(UILabel *)otherContentLabel line:(UIView *)line
{
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.equalTo(lastView.mas_bottom).offset(15);
    }];
    
    [exceptNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.equalTo(titleLabel.mas_bottom).offset(13);
    }];
    
    [exceptTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(exceptNameLabel.mas_trailing).offset(10);
        make.trailing.lessThanOrEqualTo(-10);
        make.top.equalTo(exceptNameLabel);
    }];
    
    [validNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(exceptNameLabel);
        make.top.equalTo(exceptTimeLabel.mas_bottom).offset(13);
    }];
    
    [validTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(validNameLabel.mas_trailing).offset(10);
        make.trailing.lessThanOrEqualTo(-10);
        make.top.equalTo(validNameLabel);
    }];
    
    if (otherContentLabel != nil) {
        [otherContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(10);
            make.trailing.mas_equalTo(-10);
            make.top.equalTo(validTimeLabel.mas_bottom).offset(13);
        }];
        
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(10);
            make.trailing.mas_equalTo(-10);
            make.height.mas_equalTo(0.5);
            make.top.equalTo(otherContentLabel.mas_bottom).offset(15);
        }];
    }else{
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(10);
            make.trailing.mas_equalTo(-10);
            make.height.mas_equalTo(0.5);
            make.top.equalTo(validTimeLabel.mas_bottom).offset(15);
        }];
    }
    
    
    
}

#pragma mark - 添加 团购 餐厅名称  label 约束
- (void)addMasonryWithLastView:(UIView *)lastView resNameTitleLabel:(UILabel *)titleLabel resNameLabel:(UILabel *)resNameLabel line:(UIView *)line
{
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.top.equalTo(lastView.mas_bottom).offset(15);
    }];
    
    [resNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(10);
        make.top.equalTo(titleLabel.mas_bottom).offset(13);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.top.equalTo(resNameLabel.mas_bottom).offset(15);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark - creat control
- (UILabel *)creatLabelWithTextColor:(UIColor *)textColor Font:(UIFont *)textFont NumberLines:(NSInteger)numLines
{
    UILabel *l = [[UILabel alloc] init];
    l.textColor = textColor;
    l.font = textFont;
    l.numberOfLines = numLines;
    l.backgroundColor = [UIColor clearColor];
    l.lineBreakMode = NSLineBreakByTruncatingTail;
    l.textAlignment = NSTextAlignmentNatural;
    
    return l;
}

- (UIView *)creatLine
{
    UIView * v = [[UIView alloc] init];
    v.backgroundColor = UIColorFromRGB(0xdddddd, 1);
    return v;
}

- (UIButton *)creatButtonWithTitle:(NSString *)title
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = UIColorFromRGB(0xff7a21, 1);
    btn.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:12];
    [btn setTitleColor:UIColorFromRGB(0xffffff, 1) forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.layer.cornerRadius = 4;
    btn.layer.masksToBounds = YES;
    
    return btn;
}


@end
